﻿using System.Xml.Linq;

namespace Comdiv.UXmlDiff {
	public static class XDiffAnnotationExtension {
		static XDiffIdGenerator ider = new XDiffIdGenerator();
		public static XDiffAnnotation Diff(this XObject obj, bool safemode = false) {
			var result = obj.Annotation<XDiffAnnotation>();
			if(null==result) {
				result = new XDiffAnnotation();
				obj.AddAnnotation(result);
			}
			if(string.IsNullOrWhiteSpace(result.Id)) {
				result.Id = ider.GenerateId(obj,safemode);
			}
			result.XObj = result.XObj ?? obj;
			return result;
		}
	}
}